package com.suray.wcs.service.system.scheduled;


import com.suray.wcs.res.enums.RgvStatus;
import com.suray.wcs.res.enums.RgvType;
import com.suray.wcs.service.init.SystemInit;
import com.suray.wcs.service.pojo.Rgv;
import com.suray.wcs.service.pojo.rgv.rgv.protocol.message.RgvSendClearOrderMessage;
import com.suray.wcs.service.pojo.rgv.rgv.protocol.message.RgvSendScadaMessage;
import com.suray.wcs.service.util.WcsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 定时任务调度：定时获取车辆SCADA参数
 *
 * @author lk
 */
@Component("ScadaTask")
public class ScadaTask {
    private Logger logger = LoggerFactory.getLogger(DeleteLogTask.class);

    public void scadaTask() {
        try {
            for (Rgv rgv : SystemInit.RGVS) {
                if (rgv.checkRgvType(RgvType.FIVE_POINT_FOUR_TL) && rgv.getRgvStatus() != RgvStatus.OFF_LINE) {
                    RgvSendScadaMessage scadaMessage = new RgvSendScadaMessage(rgv);
                    rgv.getRgvProtocol().comm(scadaMessage);
                    RgvSendClearOrderMessage clearOrderMessage = new RgvSendClearOrderMessage(rgv);
                    rgv.getRgvProtocol().comm(clearOrderMessage);

                }
            }
        } catch (IOException e) {
            WcsUtil.exceptionLog(e, this.getClass());
        } catch (Exception e) {
            logger.error("SCADA数据监控出现异常", e);
        }
    }

}
